<%@ page import="com.actimind.actitime.beans.UserBean,
                 com.actimind.actitime.Keys,
                 com.actimind.actitime.util.TimeUtils,
                 java.util.Set,
                 java.util.Iterator,
                 java.util.Date,
                 com.actimind.actitime.calendar.AbstractCalendarForm,
                 com.actimind.actitime.calendar.AbstractCalendarForm"%><%@ page errorPage="/error.jsp" %>
<%@ taglib uri="/WEB-INF/at.tld" prefix="at" %>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>

<bean:define id="form" scope="session" name="WorkingDaysForm" type="com.actimind.actitime.administration.WorkingDaysForm"/>
<html>
  <head>
    <title><bean:write name="title-prefix" scope="application"/> Manage Working and Nonworking Days</title>
    <link rel="stylesheet" href="<html:rewrite page='/css/at.css'/>" type="text/css">
    <link rel="stylesheet" href="<html:rewrite page='/css/calendar_nn.css'/>" type="text/css">
    <style type="text/css"> @import url("<html:rewrite page='/css/calendar_large.css'/>"); </style>
    <script language="JavaScript" src="<html:rewrite page='/js/at.js'/>"></script>
    <script language="JavaScript" src="<html:rewrite page='/js/calendar.js?r=1'/>"></script>

<script language="JavaScript">

function selectDate(dateStr)
{
    var date = strToDate(dateStr);
    location.href = '<html:rewrite href='workingdays.do?daySelected=true&dateStr='/>' + makeDate(date.getFullYear(), date.getMonth() + 1, date.getDate());
}

function dateChanged(value)
{
    var d = new Date();
    var month = document.WorkingDaysForm.month.options[document.WorkingDaysForm.month.selectedIndex].value;
    d.setMonth(month - 1);
    var year = document.WorkingDaysForm.year.options[document.WorkingDaysForm.year.selectedIndex].value;
    location.href = '<html:rewrite href='workingdays.do?daySelected=false&dateStr='/>' +
        makeDate(year, d.getMonth() + 1, 1);
}

function makeDate(year, month, day)
{
    return year + '-' + month + '-' + day;
}

var invertedDays = new Array(<%=form.getInvertedDaysAsCSV()%>);
var cal = createLayoutCalendar('',
  '<%=TimeUtils.toString(form.getDate(), AbstractCalendarForm.DATE_FORMAT) %>',
  '',
  '', 'selectDate', '<html:rewrite page="/img/pixel.gif"/>',
  '<%=form.getCalendarPreferences().getCalendarLayout()%>',
  invertedDays);
  cal.setWeekDays(new Array("S", "M", "T", "W", "T", "F", "S"));
  cal.setHilightCurrentDay(<%=form.isDaySelected()%>);
  cal.setLinkCurrentDay(<%=!form.isDaySelected()%>);
  cal.setHeader(true);


</script>
</head>

<body bgcolor="#ffffff" topmargin="0" leftmargin="0" marginheight="0" marginwidth="0">
<jsp:include page="../top.jsp" flush="false">
    <jsp:param name="pageSection" value="administration" />
    <jsp:param name="pageAction" value="workdays" />
</jsp:include>
<html:form scope="session" action="/administration/workingdays.do" method="post">
<table cellspacing="0" cellpadding="0" align="center" valign="top" border="0">
    <tr align="left">
        <td colspan="4" align="left"><br class="small">
             &nbsp<span class="pagetitle">Working and Nonworking Days</span><br>
             <at:errors/>
             <at:messages id="message" message="true">&nbsp;<span class="successmsg"><bean:write name="message"/></span></at:messages>
             <br>
        </td>
    </tr>
<tr>
<td align="left" valign="top">
<table cellpadding="2" cellspacing="4" valign="top" border="0" bgcolor="#ffffff" width="100%">
    <tr>
        <td valign="top" colspan="4" align="left" class="formblocktitle">
            Select a Day to Modify
        </td>
    </tr>
    <tr><td colspan="4"><html:img page="/img/pixel.gif" width="1" height="4" alt=""/></td></tr>
    <tr>
        <td align="left">&nbsp;</td>
        <td align="left">
        <logic:equal property="previousMonthAvailable" value="true" name="form">
            <a href="<html:rewrite href='workingdays.do?daySelected=false&dateStr='/><%=form.getPreviousMonthAsString()%>"><html:img border="0" page="/img/prev.gif" align="left" hspace="4"/></a>
        </logic:equal>
        <logic:equal property="previousMonthAvailable" value="false" name="form"><html:img border="0" width="15" height="14" hspace="4" page="/img/pixel.gif" /></logic:equal>
        </td>
        <td align="center" nowrap="1">
                   <html:select property="month" name="form" onchange="dateChanged()">
                       <html:option value="1">January</html:option>
                       <html:option value="2">February</html:option>
                       <html:option value="3">March</html:option>
                       <html:option value="4">April</html:option>
                       <html:option value="5">May</html:option>
                       <html:option value="6">June</html:option>
                       <html:option value="7">July</html:option>
                       <html:option value="8">August</html:option>
                       <html:option value="9">September</html:option>
                       <html:option value="10">October</html:option>
                       <html:option value="11">November</html:option>
                       <html:option value="12">December</html:option>
                   </html:select>
                    <%
                            int yearFrom = form.getYearFrom();
                            int yearTo = form.getYearTo();
                    %>
                    <html:select property="year" name="form" onchange="dateChanged()">
                    <%
                    for (int year = yearFrom; year <= yearTo; year++)
                    {
                        %><html:option value="<%=(new Integer(year)).toString()%>"><%=year%></html:option><%
                    }
                    %>
                    </html:select>
        </td>
        <td align="left">
        <logic:equal property="nextMonthAvailable" value="true" name="form">
            <a href="<html:rewrite href='workingdays.do?daySelected=false&dateStr='/><%=form.getNextMonthAsString()%>"><html:img border="0" page="/img/next.gif" align="left" hspace="4"/></a>
        </logic:equal>
        <logic:equal property="nextMonthAvailable" value="false" name="form"><html:img border="0" width="15" height="14" hspace="4" page="/img/pixel.gif" /></logic:equal>
        </td>
    </tr>
    <tr>
        <td>&nbsp;</td>
        <td colspan="3" align="right" valign="top" nowrap="1">
        <script language="JavaScript">
        document.writeln(cal.getCalendarHTML());
        </script>
    </tr>
    <tr>
        <td>&nbsp;</td>
        <td colspan="3" align="left" class="formblocktitle">
            &nbsp;&nbsp;<b>Today: <%=TimeUtils.toString(new Date(), "MMMM dd, yyyy")%></b>
        </td>
    </tr>
    <tr>
        <td>&nbsp;</td>
        <td align="left" colspan="3">
                    <table border="0" cellspacing="6">
                        <tr>
                            <td class="calendarWorkingDay"><html:img page="/img/pixel.gif" width="20" height="20" alt=""/></td>
                            <td class="formcomment"> - Working day</td>
                        </tr>
                        <tr>
                            <td class="calendarWeekendDay"><html:img page="/img/pixel.gif" width="20" height="20" alt=""/></td>
                            <td class="formcomment"> - Nonworking day</td>
                        </tr>
                        <tr>
                            <td class="calendarCurrentDay"><html:img page="/img/pixel.gif" width="20" height="20" alt=""/></td>
                            <td class="formcomment"> - Selected day</td>
                        </tr>
                    </table>
        </td>
    </tr>
    <tr>
        <td align="left" colspan="4">
        </td>
    </tr>
</table>
</td>
<td>
   <html:img page="/img/pixel.gif" width="20" height="1"/>
</td>
<td align="left" valign="top">
        <logic:equal value="true" property="daySelected" name="form">
            <html:hidden property="daySelected" />
            <table border="0" width="100%" cellspacing="2" cellpadding="4" >
                <tr>
                    <td class="formblocktitle">
                       Properties of the Selected Day
                    </td>
                </tr>
                <tr><td><html:img page="/img/pixel.gif" width="1" height="4" alt=""/></td></tr>
                <tr width="100%">
                    <td class="formbuttonpane" width="100%">
                        <table border="0" cellspacing="0" cellpadding="0" width="100%">
                            <tr>
                                <td>
                                    <html:img page="/img/pixel.gif" width="20" height="1" alt=""/>
                                </td>
                                <td align="left" class="formblocktitle" nowrap="1">
                                    You have selected:
                                </td>
                                <td>
                                   <html:img page="/img/pixel.gif" width="20" height="1" alt="1"/>
                                </td>
                                <td align="left" nowrap="1">
                                    <span class="text"><%=form.getDateAsString("MMMM dd, yyyy")%></span>
                                </td>
                                <td>
                                    <html:img page="/img/pixel.gif" width="186" height="1" alt=""/>
                                </td>
                            </tr>
                            <tr>
                                <td>
                                    <html:img page="/img/pixel.gif" width="20" height="1" alt=""/>
                                </td>
                                <td align="left" class="formblocktitle" nowrap="1">
                                    Status:
                                </td>
                                <td>
                                    &nbsp;
                                </td>
                                <td align="left" nowrap="1">
                                    <logic:equal value="true" name="form" property="workingDay">
                                      <span class="text">Working day <logic:equal value="true" property="workingDayDefault" name="form">(default)</logic:equal></span>
                                    </logic:equal>
                                    <logic:equal value="false" name="form" property="workingDay">
                                       <span class="text">Nonworking day <logic:equal value="false" property="workingDayDefault" name="form">(default)</logic:equal></span>
                                    </logic:equal>
                                </td>
                                <td>
                                    <html:img page="/img/pixel.gif" width="186" height="1" alt=""/>
                                </td>
                            </tr>
                        </table>
                    </td>
                </tr>
                <tr><td><html:img page="/img/pixel.gif" width="1" height="4" alt=""/></td></tr>
                <tr>
                    <td class="formblocktitle">
                       Edit Day Properties:
                    </td>
                </tr>
                <tr>
                    <td>
                        <table border="0" cellspacing="4">
                            <tr>
                              <td>&nbsp;</td>
                              <td><html:radio property="workingDay" value="true" /></td>
                              <td><span class="text">Working day
                                    <logic:equal value="true" property="workingDayDefault" name="form">(default)</logic:equal></span></td>
                            </tr>
                            <tr>
                              <td>&nbsp;</td>
                              <td><html:radio property="workingDay" value="false" /></td>
                              <td><span class="text">Nonworking day
                                    <logic:equal value="false" property="workingDayDefault" name="form">(default)</logic:equal></span></td>
                            </tr>
                        </table>
                    </td>
                </tr>
                <tr><td><html:img page="/img/pixel.gif" width="1" height="8" alt=""/></td></tr>
                <tr>
                   <td width="100%" class="formbuttonpane" align="center">
                        <table border="0" cellpadding="2">
                            <tr>
                                <td  align="center" width="100%">
                                    <html:submit value="  Save Changes  " />
                                </td>
                            </tr>
                        </table>
                   </td>
                </tr>
            </table>
        </logic:equal>
            <table width="100%">
                <tr>
                    <td>
                        <html:img page="/img/pixel.gif" width="512" height="1" alt="" border="0"/>
                    </td>
                </tr>
            </table>
</td>
</tr>
</table><input type="hidden" name="submitted" value="1" />
</html:form>
</html>